class HomeController < ApplicationController

  def index
    # @hot_project = Recommend.all.default_order.includes(:project).limit(6)
    @hot_project = Project.includes(:money_requires).where('money_requires.status' => 'opened').limit(8)
    @new_project = Project.includes(:money_requires).where('money_requires.status' => ['leader_needed', 'leader_need_confirmed']).limit(8)
    @ok_project = Project.includes(:money_requires).where('money_requires.status' => 'closed').limit(4)
    # @hot_project = MoneyRequire.where(:status => 'opened').order(sort: :desc).limit(8)
    # @new_project = MoneyRequire.where(:status => ['leader_needed', 'leader_need_confirmed']).order(sort: :desc).limit(8)
    # @ok_project = MoneyRequire.where(:status => 'closed').order(sort: :desc).limit(4)
    @aps1 = Ap.where(:isopen=>true,:place=>0).order(sort: :desc).limit(5)
    @aps2 = Ap.where(:isopen=>true,:place=>1).order(sort: :desc).first
    @aps3 = Ap.where(:isopen=>true,:place=>2).order(sort: :desc).first
    # @investors = Investor.default_order.passed.limit(3)
    # @person_requires = PersonRequire.all.limit(3)
    render 'nologin'
  end

  def welcome
    @recommends = Recommend.all.default_order.includes(:project).limit(3)
  end

  def search
    @q = params[:q]
    @projects = Project.search do
      fulltext "*#{params[:q]}*"
      paginate page: 1, per_page: 5
    end.results

    @investors = Investor.search do
      fulltext "*#{params[:q]}*"
      paginate page: 1, per_page: 5
      with(:status, 'passed')
    end.results

    @person_requires = PersonRequire.search do
      fulltext "*#{params[:q]}*"
      paginate page: 1, per_page: 5
      with(:status, 'opened')
    end.results
  end

end
